﻿@addTagHelper *, WebVella.Erp.Plugins.Core
@addTagHelper *, WebVella.Erp.Web
@addTagHelper *, WebVella.TagHelpers
@using WebVella.Erp.Web.Utils;
@using WebVella.Erp.Web.Components;
@using WebVella.Erp.Web.Models;
@{
	var options = (PcModal.PcModalOptions)ViewBag.Options;
	var node = (PageBodyNode)ViewBag.Node;
	var componentContext = (PageComponentContext)ViewBag.ComponentContext;
	var bodyNodes = node.Nodes.FindAll(x => x.ContainerId == "body");
	var footerNodes = node.Nodes.FindAll(x => x.ContainerId == "footer");
}

<wv-modal title="@ViewBag.ProcessedTitle" id="@options.Id" size="@options.Size" position="@options.Position" backdrop="@options.Backdrop" is-visible="(bool)ViewBag.IsVisible">
	<wv-modal-body>
		@foreach (var childNode in bodyNodes)
		{
			var nodeComponentName = "";
			if (childNode != null)
			{
				var nameArray = childNode.ComponentName.Split('.');
				nodeComponentName = nameArray[nameArray.Length - 1];
			}
			if (!String.IsNullOrWhiteSpace(nodeComponentName))
			{
				var childOptions = PageUtils.ConvertStringToJObject(childNode.Options.ToString());
				var pcContext = new PageComponentContext(childNode, componentContext.DataModel, ComponentMode.Display, childOptions, componentContext.Items);
				@await Component.InvokeAsync(nodeComponentName, new { context = pcContext })
			}
		}		
	</wv-modal-body>
	<wv-modal-footer>
		@foreach (var childNode in footerNodes)
		{
			var nodeComponentName = "";
			if (childNode != null)
			{
				var nameArray = childNode.ComponentName.Split('.');
				nodeComponentName = nameArray[nameArray.Length - 1];
			}
			if (!String.IsNullOrWhiteSpace(nodeComponentName))
			{
				var childOptions = PageUtils.ConvertStringToJObject(childNode.Options.ToString());
				var pcContext = new PageComponentContext(childNode, componentContext.DataModel, ComponentMode.Display, childOptions, componentContext.Items);
				@await Component.InvokeAsync(nodeComponentName, new { context = pcContext })
			}
		}
	</wv-modal-footer>
</wv-modal>

